using Firestarter.DB.Schema.Logic;
using FireStarterModeller.BO;
using NUnit.Framework;

namespace Firestarter.DB_DomainModel.Logic.Test
{
    [TestFixture]
    public class TestDBTypeToDMPropertyTypeMapper : TestBase
    {
        //TODO Mark 29 Jul 2009: When DBType does not have a conversion, then it should create a property type to match it?

        [Test]
        public void Test_StandardMapping_Bit()
        {
            //---------------Set up test pack-------------------
            IPropertyTypeStorer propertyTypeStorer = new PropertyTypeStorerStub();
            IDBTypeToDMPropertyTypeMapper mapper =
                new DBTypeToDMPropertyTypeMapper(propertyTypeStorer);

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            DMPropertyType type = mapper.GetDMPropertyType(DBDataTypes.BIT, null);
            //---------------Test Result -----------------------
            Assert.AreEqual("System", type.AssemblyName);
            Assert.AreEqual("Boolean", type.PropertyTypeName);
        }
        [Test]
        public void Test_StandardMapping_Bit1_ShouldRetBool()
        {
            //---------------Set up test pack-------------------
            IPropertyTypeStorer propertyTypeStorer = new PropertyTypeStorerStub();
            IDBTypeToDMPropertyTypeMapper mapper =
                new DBTypeToDMPropertyTypeMapper(propertyTypeStorer);

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            DMPropertyType type = mapper.GetDMPropertyType(DBDataTypes.BIT, 1);
            //---------------Test Result -----------------------
            Assert.AreEqual("System", type.AssemblyName);
            Assert.AreEqual("Boolean", type.PropertyTypeName);
        }
        [Test]
        public void Test_StandardMapping_BitNeg1_ShouldRetBool()
        {
            //---------------Set up test pack-------------------
            IPropertyTypeStorer propertyTypeStorer = new PropertyTypeStorerStub();
            IDBTypeToDMPropertyTypeMapper mapper =
                new DBTypeToDMPropertyTypeMapper(propertyTypeStorer);

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            DMPropertyType type = mapper.GetDMPropertyType(DBDataTypes.BIT, -1);
            //---------------Test Result -----------------------
            Assert.AreEqual("System", type.AssemblyName);
            Assert.AreEqual("Boolean", type.PropertyTypeName);
        }

        [Test]
        public void Test_StandardMapping_TimeStamp()
        {
            //---------------Set up test pack-------------------
            IPropertyTypeStorer propertyTypeStorer = new PropertyTypeStorerStub();
            IDBTypeToDMPropertyTypeMapper mapper =
                new DBTypeToDMPropertyTypeMapper(propertyTypeStorer);

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            DMPropertyType type = mapper.GetDMPropertyType(DBDataTypes.TIMESTAMP, null);
            //---------------Test Result -----------------------
            Assert.AreEqual("System", type.AssemblyName);
            Assert.AreEqual("DateTime", type.PropertyTypeName);
        }

        [Test]
        public void Test_StandardMapping_Binary()
        {
            //---------------Set up test pack-------------------
            IPropertyTypeStorer propertyTypeStorer = new PropertyTypeStorerStub();
            IDBTypeToDMPropertyTypeMapper mapper =
                new DBTypeToDMPropertyTypeMapper(propertyTypeStorer);

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            DMPropertyType type = mapper.GetDMPropertyType(DBDataTypes.BINARY, null);
            //---------------Test Result -----------------------
            Assert.AreEqual("System", type.AssemblyName);
            Assert.AreEqual("Byte[]", type.PropertyTypeName);
        }

        [Test]
        public void Test_StandardMapping_VarBinary()
        {
            //---------------Set up test pack-------------------
            IPropertyTypeStorer propertyTypeStorer = new PropertyTypeStorerStub();
            IDBTypeToDMPropertyTypeMapper mapper =
                new DBTypeToDMPropertyTypeMapper(propertyTypeStorer);

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            DMPropertyType type = mapper.GetDMPropertyType(DBDataTypes.VARBINARY, null);
            //---------------Test Result -----------------------
            Assert.AreEqual("System", type.AssemblyName);
            Assert.AreEqual("Byte[]", type.PropertyTypeName);
        }

        [Test]
        public void Test_StandardMapping_DateTime()
        {
            //---------------Set up test pack-------------------
            IPropertyTypeStorer propertyTypeStorer = new PropertyTypeStorerStub();
            IDBTypeToDMPropertyTypeMapper mapper =
                new DBTypeToDMPropertyTypeMapper(propertyTypeStorer);

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            DMPropertyType type = mapper.GetDMPropertyType(DBDataTypes.DATETIME, null);
            //---------------Test Result -----------------------
            Assert.AreEqual("System", type.AssemblyName);
            Assert.AreEqual("DateTime", type.PropertyTypeName);
        }

        [Test]
        public void Test_StandardMapping_Decimal()
        {
            //---------------Set up test pack-------------------
            IPropertyTypeStorer propertyTypeStorer = new PropertyTypeStorerStub();
            IDBTypeToDMPropertyTypeMapper mapper =
                new DBTypeToDMPropertyTypeMapper(propertyTypeStorer);

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            DMPropertyType type = mapper.GetDMPropertyType(DBDataTypes.DECIMAL, null);
            //---------------Test Result -----------------------
            Assert.AreEqual("System", type.AssemblyName);
            Assert.AreEqual("Decimal", type.PropertyTypeName);
        }

        [Test]
        public void Test_StandardMapping_Numeric()
        {
            //---------------Set up test pack-------------------
            IPropertyTypeStorer propertyTypeStorer = new PropertyTypeStorerStub();
            IDBTypeToDMPropertyTypeMapper mapper =
                new DBTypeToDMPropertyTypeMapper(propertyTypeStorer);

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            DMPropertyType type = mapper.GetDMPropertyType(DBDataTypes.NUMERIC, null);
            //---------------Test Result -----------------------
            Assert.AreEqual("System", type.AssemblyName);
            Assert.AreEqual("Decimal", type.PropertyTypeName);
        }

        [Test]
        public void Test_StandardMapping_Double()
        {
            //---------------Set up test pack-------------------
            IPropertyTypeStorer propertyTypeStorer = new PropertyTypeStorerStub();
            IDBTypeToDMPropertyTypeMapper mapper =
                new DBTypeToDMPropertyTypeMapper(propertyTypeStorer);

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            DMPropertyType type = mapper.GetDMPropertyType(DBDataTypes.DOUBLE, null);
            //---------------Test Result -----------------------
            Assert.AreEqual("System", type.AssemblyName);
            Assert.AreEqual("Double", type.PropertyTypeName);
        }

        [Test]
        public void Test_StandardMapping_Varchar()
        {
            //---------------Set up test pack-------------------
            IPropertyTypeStorer propertyTypeStorer = new PropertyTypeStorerStub();
            IDBTypeToDMPropertyTypeMapper mapper =
                new DBTypeToDMPropertyTypeMapper(propertyTypeStorer);

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            DMPropertyType type = mapper.GetDMPropertyType(DBDataTypes.VARCHAR, null);
            //---------------Test Result -----------------------
            Assert.AreEqual("System", type.AssemblyName);
            Assert.AreEqual("String", type.PropertyTypeName);
        }

        [Test]
        public void Test_StandardMapping_SmallInt()
        {
            //---------------Set up test pack-------------------
            IPropertyTypeStorer propertyTypeStorer = new PropertyTypeStorerStub();
            IDBTypeToDMPropertyTypeMapper mapper =
                new DBTypeToDMPropertyTypeMapper(propertyTypeStorer);

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            DMPropertyType type = mapper.GetDMPropertyType(DBDataTypes.SMALLINT, null);
            //---------------Test Result -----------------------
            Assert.AreEqual("System", type.AssemblyName);
            Assert.AreEqual("Int16", type.PropertyTypeName);
        }

        [Test]
        public void Test_StandardMapping_Integer()
        {
            //---------------Set up test pack-------------------
            IPropertyTypeStorer propertyTypeStorer = new PropertyTypeStorerStub();
            IDBTypeToDMPropertyTypeMapper mapper = new DBTypeToDMPropertyTypeMapper(propertyTypeStorer);

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            DMPropertyType type = mapper.GetDMPropertyType(DBDataTypes.INTEGER, null);
            //---------------Test Result -----------------------
            Assert.AreEqual("System", type.AssemblyName);
            Assert.AreEqual("Int32", type.PropertyTypeName);
        }

        [Test]
        public void Test_StandardMapping_BigInt()
        {
            //---------------Set up test pack-------------------
            IPropertyTypeStorer propertyTypeStorer = new PropertyTypeStorerStub();
            IDBTypeToDMPropertyTypeMapper mapper =
                new DBTypeToDMPropertyTypeMapper(propertyTypeStorer);

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            DMPropertyType type = mapper.GetDMPropertyType(DBDataTypes.BIGINT, null);
            //---------------Test Result -----------------------
            Assert.AreEqual("System", type.AssemblyName);
            Assert.AreEqual("Int64", type.PropertyTypeName);
        }

        [Test]
        public void Test_StandardMapping_TinyInt()
        {
            //---------------Set up test pack-------------------
            IPropertyTypeStorer propertyTypeStorer = new PropertyTypeStorerStub();
            IDBTypeToDMPropertyTypeMapper mapper =
                new DBTypeToDMPropertyTypeMapper(propertyTypeStorer);

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            DMPropertyType type = mapper.GetDMPropertyType(DBDataTypes.TINYINT, null);
            //---------------Test Result -----------------------
            Assert.AreEqual("System", type.AssemblyName);
            Assert.AreEqual("Byte", type.PropertyTypeName);
        }
        [Test]
        public void Test_StandardMapping_TinyInt_Length1_ShouldBeBool()
        {
            //---------------Set up test pack-------------------
            IPropertyTypeStorer propertyTypeStorer = new PropertyTypeStorerStub();
            IDBTypeToDMPropertyTypeMapper mapper =
                new DBTypeToDMPropertyTypeMapper(propertyTypeStorer);

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            DMPropertyType type = mapper.GetDMPropertyType(DBDataTypes.TINYINT, 1);
            //---------------Test Result -----------------------
            Assert.AreEqual("System", type.AssemblyName);
            Assert.AreEqual("Boolean", type.PropertyTypeName);
        }
        [Test]
        public void Test_StandardMapping_TinyInt_LengthNeg1_ShouldBeBool()
        {
            //---------------Set up test pack-------------------
            IPropertyTypeStorer propertyTypeStorer = new PropertyTypeStorerStub();
            IDBTypeToDMPropertyTypeMapper mapper =
                new DBTypeToDMPropertyTypeMapper(propertyTypeStorer);

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            DMPropertyType type = mapper.GetDMPropertyType(DBDataTypes.TINYINT, -1);
            //---------------Test Result -----------------------
            Assert.AreEqual("System", type.AssemblyName);
            Assert.AreEqual("Boolean", type.PropertyTypeName);
        }
        [Test]
        public void Test_StandardMapping_TinyInt_Length3_ShouldBeByte()
        {
            //---------------Set up test pack-------------------
            IPropertyTypeStorer propertyTypeStorer = new PropertyTypeStorerStub();
            IDBTypeToDMPropertyTypeMapper mapper =
                new DBTypeToDMPropertyTypeMapper(propertyTypeStorer);

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            DMPropertyType type = mapper.GetDMPropertyType(DBDataTypes.TINYINT, 3);
            //---------------Test Result -----------------------
            Assert.AreEqual("System", type.AssemblyName);
            Assert.AreEqual("Byte", type.PropertyTypeName);
        }

        [Test]
        public void Test_StandardMapping_Single()
        {
            //---------------Set up test pack-------------------
            IPropertyTypeStorer propertyTypeStorer = new PropertyTypeStorerStub();
            IDBTypeToDMPropertyTypeMapper mapper =
                new DBTypeToDMPropertyTypeMapper(propertyTypeStorer);

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            DMPropertyType type = mapper.GetDMPropertyType(DBDataTypes.SINGLE, null);
            //---------------Test Result -----------------------
            Assert.AreEqual("System", type.AssemblyName);
            Assert.AreEqual("Single", type.PropertyTypeName);
        }

        [Test]
        public void Test_StandardMapping_Text()
        {
            //---------------Set up test pack-------------------
            IPropertyTypeStorer propertyTypeStorer = new PropertyTypeStorerStub();
            IDBTypeToDMPropertyTypeMapper mapper =
                new DBTypeToDMPropertyTypeMapper(propertyTypeStorer);

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            DMPropertyType type = mapper.GetDMPropertyType(DBDataTypes.TEXT, null);
            //---------------Test Result -----------------------
            Assert.AreEqual("System", type.AssemblyName);
            Assert.AreEqual("String", type.PropertyTypeName);
        }

        [Test]
        public void Test_StandardMapping_Char()
        {
            //---------------Set up test pack-------------------
            IPropertyTypeStorer propertyTypeStorer = new PropertyTypeStorerStub();
            IDBTypeToDMPropertyTypeMapper mapper =
                new DBTypeToDMPropertyTypeMapper(propertyTypeStorer);

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            DMPropertyType type = mapper.GetDMPropertyType(DBDataTypes.CHAR, null);
            //---------------Test Result -----------------------
            Assert.AreEqual("System", type.AssemblyName);
            Assert.AreEqual("String", type.PropertyTypeName);
        }

        [Test]
        public void Test_StandardMapping_LongVarBinary()
        {
            //---------------Set up test pack-------------------
            IPropertyTypeStorer propertyTypeStorer = new PropertyTypeStorerStub();
            IDBTypeToDMPropertyTypeMapper mapper =
                new DBTypeToDMPropertyTypeMapper(propertyTypeStorer);

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            DMPropertyType type = mapper.GetDMPropertyType(DBDataTypes.LONGVARBINARY, null);
            //---------------Test Result -----------------------
            Assert.AreEqual("System", type.AssemblyName);
            Assert.AreEqual("Byte[]", type.PropertyTypeName);
        }

        [Test]
        public void Test_StandardMapping_MediumText()
        {
            //---------------Set up test pack-------------------
            IPropertyTypeStorer propertyTypeStorer = new PropertyTypeStorerStub();
            IDBTypeToDMPropertyTypeMapper mapper =
                new DBTypeToDMPropertyTypeMapper(propertyTypeStorer);

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            DMPropertyType type = mapper.GetDMPropertyType(DBDataTypes.MEDIUMTEXT, null);
            //---------------Test Result -----------------------
            Assert.AreEqual("System", type.AssemblyName);
            Assert.AreEqual("String", type.PropertyTypeName);
        }

        [Test]
        public void Test_StandardMapping_LongText()
        {
            //---------------Set up test pack-------------------
            IPropertyTypeStorer propertyTypeStorer = new PropertyTypeStorerStub();
            IDBTypeToDMPropertyTypeMapper mapper =
                new DBTypeToDMPropertyTypeMapper(propertyTypeStorer);

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            DMPropertyType type = mapper.GetDMPropertyType(DBDataTypes.LONGTEXT, null);
            //---------------Test Result -----------------------
            Assert.AreEqual("System", type.AssemblyName);
            Assert.AreEqual("String", type.PropertyTypeName);
        }

        [Test]
        public void Test_StandardMapping_Time()
        {
            //---------------Set up test pack-------------------
            IPropertyTypeStorer propertyTypeStorer = new PropertyTypeStorerStub();
            IDBTypeToDMPropertyTypeMapper mapper =
                new DBTypeToDMPropertyTypeMapper(propertyTypeStorer);

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            DMPropertyType type = mapper.GetDMPropertyType(DBDataTypes.TIME, null);
            //---------------Test Result -----------------------
            Assert.AreEqual("System", type.AssemblyName);
            Assert.AreEqual("TimeSpan", type.PropertyTypeName);
        } 

        [Test]
        public void Test_StandardMapping_UniqueIdentifier()
        {
            //---------------Set up test pack-------------------
            IPropertyTypeStorer propertyTypeStorer = new PropertyTypeStorerStub();
            IDBTypeToDMPropertyTypeMapper mapper =
                new DBTypeToDMPropertyTypeMapper(propertyTypeStorer);

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            DMPropertyType type = mapper.GetDMPropertyType(DBDataTypes.UNIQUEIDENTIFIER, null);
            //---------------Test Result -----------------------
            Assert.AreEqual("System", type.AssemblyName);
            Assert.AreEqual("Guid", type.PropertyTypeName);
        }

        [Test]
        public void Test_GetDMPropertyType_WhenDataTypeNull_ShouldReturnString()
        {
            //---------------Set up test pack-------------------
            IPropertyTypeStorer propertyTypeStorer = new PropertyTypeStorerStub();
            IDBTypeToDMPropertyTypeMapper mapper =
                new DBTypeToDMPropertyTypeMapper(propertyTypeStorer);

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            DMPropertyType type = mapper.GetDMPropertyType(null, null);
            //---------------Test Result -----------------------
            Assert.AreEqual("System", type.AssemblyName);
            Assert.AreEqual("String", type.PropertyTypeName);
        }
    }

    internal class PropertyTypeStorerStub : IPropertyTypeStorer
    {
        public DMPropertyType GetDMPropertyType(string assemblyName, string propertyTypeName)
        {
            return new DMPropertyType {AssemblyName = assemblyName, PropertyTypeName = propertyTypeName};
        }
    }

    
}
